const fs = require('fs');
const child_process = require('child_process');

// cache sub process output and return to callback in father process
for (var i = 0; i<3; i++) {
	var wp = child_process.exec('node demo30childProcess.js ' + i, (err, stdout, stderr) => {
		if (err) {
			console.log(err.stack);
			console.log('Error code:', err.code);
			console.log('Signal:', err.signal);
		}
		console.log('stdout =>', stdout);
		console.log('stderr =>', stderr);
	});
	wp.on('exit', code => {
		console.log('child process exit => ', code);
	});
}
